package com.justnow.offer;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution {
    public String triCoding(int num) {
        Map<Integer,  Character> map = new HashMap<>();
        map.put(0, '@');
        map.put(1, '$');
        map.put(2, '&');
        StringBuilder stringBuilder = new StringBuilder();
        List<Integer> list = new ArrayList<>();

        while (num > 0) {
            list.add(num % 3);
            num = num / 3;
        }
        int size = list.size();

        for (int i = size - 1; i >= 0; i--) {
            stringBuilder.append(map.get(list.get(i)));
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String s = solution.triCoding(123);
        System.out.println(s);
    }
}
